home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / lib / cdf_o_if.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-28  |  30.4 KB  |  958 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF            CDF OBSOLETE interface (for V1.1 applications).
  4. *
  5. *  Version 2.4, 28-Feb-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0  22-Jan-91, J Love    Original version (for CDF V2.0).
  10. *   V2.0  31-May-91, J Love    Renamed (was CDF_V2_OBSOLETE_IF.C).  Changed
  11. *                for new CDF V2.1 internal structures and to
  12. *                call INTERNAL i/f directly.
  13. *   V2.1  12-Jun-91, J Love    CDF_EPOCH made a data type.
  14. *   V2.2  30-Jul-91, J Love    Use 'CDFlib'.  Added 'cdfdist.h' include.
  15. *                Start CDFid's at 1 (rather than 0).
  16. *   V2.3  24-Sep-91, J Love    Modified for IBM-PC port.
  17. *   V2.4  28-Feb-92, J Love    CDF V2.2.
  18. *
  19. ******************************************************************************/
  20.  
  21. #if defined(vms)        /* THIS FILE IS ONLY USED ON VMS SYSTEMS */
  22.  
  23. /******************************************************************************
  24. *
  25. *  Notes:
  26. *
  27. *    Because the CDF V1.1 Implementer's Guide had examples showing
  28. *  character strings being passed into the CDF library without being enclosed
  29. *  in %REF( ), it will be necessary to support both reference passing and
  30. *  descriptor passing in these cases (when passing from FORTRAN to C, the
  31. *  LINKer does not convert from descriptor passing to reference passing
  32. *  automatically is it apparently did when passing a FORTRAN character string
  33. *  to a FORTRAN byte array which occurred in CDF V1.1).
  34. *
  35. *    Character strings being passed out from the CDF library are always
  36. *  passed by reference.  This is stated in the CDF V1.1 Implementer's Guide
  37. *  and is shown in an example.
  38. *
  39. *    Character string data is generally only used with attributes but it
  40. *  can also be used with variables.  It is assumed, however, that if a
  41. *  variable is of data type STRING (CDF_CHAR), it will be passed in and out
  42. *  by reference.
  43. *
  44. ******************************************************************************/
  45.  
  46. #include "cdflib.h"
  47.  
  48.  
  49. /******************************************************************************
  50. * Macro to check CDFstatus from library call.  Note the 'return' statement.
  51. ******************************************************************************/
  52.  
  53. #define CHECKstatus(status,rcode) { \
  54. if (status < CDF_WARN) { \
  55.   *rcode = CDFrcode (status); \
  56.   return; \
  57. } \
  58. }
  59.  
  60. /******************************************************************************
  61. *  CDF_create.
  62. ******************************************************************************/
  63.  
  64. void CDF_create (CDF_name, num_dims, dim_sizes, CDF_id, rcode)
  65. void      *CDF_name;    /* in: CDF name
  66.                - in VMS, may be passed by
  67.                  reference or descriptor */
  68. long      *num_dims;    /* in: number of dimensions */
  69. long      dim_sizes[];    /* in: dimension sizes */
  70. long      *CDF_id;    /* out: CDF identifier */
  71. long      *rcode;    /* out: CDF return code */
  72. {
  73. CDFid id;
  74. *rcode = CDFrcode
  75.         (CDFlib (CREATE_, CDF_,
  76.                    DESCRtoREFnul(CDF_name,CDFV1_CDF_NAME_LEN),
  77.                    *num_dims, dim_sizes, &id,
  78.              PUT_, CDF_ENCODING_, HOST_ENCODING,
  79.                CDF_MAJORITY_, COL_MAJOR,
  80.              NULL_));
  81. if (*rcode == CDFV1_OK) *rcode = CDFrcode (initializeCDFinfo (id));
  82. *CDF_id = id + 1;
  83. return;
  84. }
  85.  
  86. /******************************************************************************
  87. *  CDF_open.
  88. ******************************************************************************/
  89.  
  90. void CDF_open (CDF_name, CDF_id, rcode)
  91. void    *CDF_name;    /* in: CDF name
  92.                    - in VMS, may be passed by
  93.                      reference or descriptor */
  94. long    *CDF_id;    /* out: CDF identifier */
  95. long    *rcode;        /* out: CDF return code */
  96. {
  97. CDFid id;
  98. *rcode = CDFrcode
  99.         (CDFlib (OPEN_, CDF_,
  100.                   DESCRtoREFnul(CDF_name,CDFV1_CDF_NAME_LEN),
  101.                   &id,
  102.              NULL_));
  103. if (*rcode == CDFV1_OK) *rcode = CDFrcode (initializeCDFinfo (id));
  104. *CDF_id = id + 1;
  105. return;
  106. }
  107.  
  108. /******************************************************************************
  109. *  CDF_inquire.
  110. ******************************************************************************/
  111.  
  112. void CDF_inquire (id, num_dims, dim_sizes,
  113.           num_recs, num_vars, num_attrs, rcode)
  114. long      *id;        /* in: CDF identifier */
  115. long      *num_dims;    /* out: number of dimensions */
  116. long      dim_sizes[];    /* out: dimension sizes */
  117. long      *num_recs;    /* out: number of records */
  118. long      *num_vars;    /* out: number of variables */
  119. long      *num_attrs;    /* out: number of attributes */
  120. long      *rcode;    /* out: CDF return code */
  121. {
  122. long        maxRec;        /* maximum record number */
  123.  
  124. *rcode = CDFrcode
  125.         (CDFlib (SELECT_, CDF_, *id - 1,
  126.              GET_, CDF_NUMDIMS_, num_dims,
  127.                CDF_DIMSIZES_, dim_sizes,
  128.                CDF_MAXREC_, &maxRec,
  129.                CDF_NUMVARS_, num_vars,
  130.                CDF_NUMATTRS_, num_attrs,
  131.              NULL_));
  132. *num_recs = maxRec + 1;
  133. return;
  134. }
  135.  
  136. /******************************************************************************
  137. *  CDF_close.
  138. ******************************************************************************/
  139.  
  140. void CDF_close (id, rcode)
  141. long    *id;        /* in: CDF identifier */
  142. long    *rcode;        /* out: CDF return code */
  143. {
  144. *rcode = CDFrcode (CDFlib (SELECT_, CDF_, *id - 1,
  145.                CLOSE_, CDF_,
  146.                NULL_));
  147. return;
  148. }
  149.  
  150. /******************************************************************************
  151. *  CDF_delete.
  152. ******************************************************************************/
  153.  
  154. void CDF_delete (CDF_name, rcode)
  155. void    *CDF_name;    /* in: CDF name
  156.                    - in VMS, may be passed by
  157.                  reference or descriptor */
  158. long    *rcode;        /* out: CDF return code */
  159. {
  160. CDFid id;
  161. *rcode = CDFrcode
  162.         (CDFlib (OPEN_, CDF_,
  163.                   DESCRtoREFnul(CDF_name,CDFV1_CDF_NAME_LEN),
  164.                   &id,
  165.              DELETE_, CDF_,
  166.              NULL_));
  167. return;
  168. }
  169.  
  170. /******************************************************************************
  171. *  CDF_attr_create.
  172. ******************************************************************************/
  173.  
  174. void CDF_attr_create (id, attr_mnemonic, data_type, num_bytes, rcode)
  175. long     *id;          /* in: CDF identifier */
  176. void     *attr_mnemonic;  /* in: attribute name
  177.                  - in VMS may be passed by reference
  178.                    or descriptor */
  179. void     *data_type;       /* in: CDF Version 1 style data type
  180.                   - in VMS may be passed by reference
  181.                     or descriptor */
  182. long      *num_bytes;       /* in: number of bytes in data type (CDF
  183.                   Version 1 style) - only applies to
  184.                   STRING (CDF_CHAR) data type */
  185. long      *rcode;       /* out: CDF return code */
  186. {
  187. long        dataType;
  188. long        attrNum;        /* C-style */
  189.  
  190. dataType = CDFV2dataType (DESCRtoREFnul(data_type,CDFV1_DATA_TYPE_LEN));
  191.  
  192. if (dataType == CDF_ILLEGAL_DATATYPE) {
  193.   *rcode = CDFV1_DEFAULT_RCODE;
  194.   return;
  195. }
  196.  
  197. *rcode = CDFrcode
  198.        (CDFlib (SELECT_, CDF_, *id - 1,
  199.             CREATE_, ATTR_, DESCRtoREFnul(attr_mnemonic,
  200.                           CDFV1_ATTR_NAME_LEN),
  201.                     VARIABLE_SCOPE_ASSUMED, &attrNum,
  202.             NULL_));
  203. if (*rcode == CDFV1_OK)
  204.   *rcode = CDFrcode (putAttrInfo (*id - 1, attrNum, dataType,
  205.                       (dataType == CDF_CHAR ? *num_bytes : 1)));
  206.  
  207. return;
  208. }
  209.  
  210. /******************************************************************************
  211. *  CDF_attr_inquire.
  212. ******************************************************************************/
  213.  
  214. void CDF_attr_inquire (id, attr_id, attr_num, attr_mnemonic, data_type,
  215.               num_bytes, num_entries, rcode)
  216. long      *id;           /* in: CDF identifier */
  217. void      *attr_id;       /* in: attribute identifier - could be
  218.                   1) attribute number, or
  219.                   2) attribute name - in VMS passed by
  220.                      reference or descriptor */
  221. long      *attr_num;       /* out: attribute number, FORTRAN-style */
  222. char      *attr_mnemonic;  /* out: attribute mnemonic - in VMS assumed to be
  223.                    passed out by reference as stated in CDF
  224.                    V1.1 Implementer's Guide */
  225. char      *data_type;       /* out: CDF Version 1 style data type,
  226.                    assumed to be passed out by reference as
  227.                    stated in CDF V1.1 Implementer's Guide */
  228. long      *num_bytes;       /* out: number of bytes in data type (CDF
  229.                    Version 1 style) */
  230. long      *num_entries;       /* out: number of entries for attribute - this was
  231.                    misleading because Version 1 actually
  232.                    returned the max. entry number (which was
  233.                    the number of entries if the entries used
  234.                    started at 1 and were contiguous) */
  235. long      *rcode;       /* out: CDF return code */
  236. {
  237.  
  238. long        attrType;
  239. char        attrName[CDF_ATTR_NAME_LEN+1];
  240. long        dataType;
  241. long        numElements;
  242. long        maxEntry;
  243. long        i;
  244. CDFstatus    status;
  245.  
  246. /******************************************************************************
  247. * First determine attribute number (indexed starting at 1 for FORTRAN).
  248. ******************************************************************************/
  249.  
  250. status = CDFV1attrNum (*id - 1, attr_id, attr_num);
  251. if (status < CDF_WARN) {
  252.   *rcode = CDFrcode (status);
  253.   return;
  254. }
  255.  
  256. /******************************************************************************
  257. * Now inquire attribute.
  258. ******************************************************************************/
  259.  
  260. *rcode = CDFrcode
  261.        (CDFlib (SELECT_, CDF_, *id - 1,
  262.                  ATTR_, *attr_num - 1,
  263.             GET_, ATTR_NAME_, attrName,
  264.               ENTRY_DATATYPE_, &attrType,
  265.               ATTR_MAXENTRY_, &maxEntry,
  266.             NULL_));
  267.  
  268. if (*rcode == CDFV1_OK)
  269.    {
  270.    /***************************************************************************
  271.    *  determine "number of entries" (Version 1 style)
  272.    ***************************************************************************/
  273.  
  274.    *num_entries = maxEntry + 1;
  275.  
  276.    /***************************************************************************
  277.    *  copy attribute name padding with blanks if necessary (note that the name
  278.    *  may be truncated since CDF V2 names can be longer than CDF V1 names)
  279.    ***************************************************************************/
  280.  
  281.    strncpy (attr_mnemonic, attrName, CDFV1_ATTR_NAME_LEN);
  282.    for (i = strlen(attrName); i < CDFV1_ATTR_NAME_LEN; i++)
  283.       attr_mnemonic[i] = ' ';
  284.  
  285.    /***************************************************************************
  286.    *  determine data_type and num_bytes
  287.    ***************************************************************************/
  288.  
  289.    *rcode = CDFrcode (getAttrInfo (*id - 1, *attr_num - 1,
  290.                    &dataType, &numElements));
  291.    if (*rcode == CDFV1_OK)
  292.      CDFV1_data_type (dataType, numElements, data_type, num_bytes);
  293.    }
  294.  
  295. return;
  296. }
  297.  
  298. /******************************************************************************
  299. *  CDF_attr_put.
  300. ******************************************************************************/
  301.  
  302. void CDF_attr_put (id, attr_id, entry_id, value, rcode)
  303. long      *id;           /* in: CDF identifier */
  304. void      *attr_id;       /* in: attribute identifier - could be
  305.                   1) attribute number, or
  306.                   2) attribute name - in VMS passed by
  307.                      reference or descriptor */
  308. void      *entry_id;       /* in: entry identifier - could be
  309.                   1) entry/variable number, or
  310.                   2) variable name - in VMS passed by
  311.                      reference or descriptor */
  312. void      *value;       /* in: attribute value, if STRING (CDF_CHAR)
  313.                   attribute, in VMS could be passed
  314.                   by reference or descriptor */
  315. long      *rcode;       /* out: CDF return code */
  316. {
  317. long        attr_num;        /* FORTRAN-style */
  318. long        entry_num;        /* FORTRAN-style */
  319. long        attrNum;        /* C-style */
  320. long        entryNum;        /* C-style */
  321. long        entryDataType;
  322. long        varDataType;
  323. char        attrName[CDF_ATTR_NAME_LEN + 1];
  324. char        varName[CDF_VAR_NAME_LEN + 1];
  325. long        numElements;
  326. CDFstatus    status;
  327.  
  328. /******************************************************************************
  329. * Determine attribute number.
  330. ******************************************************************************/
  331.  
  332. status = CDFV1attrNum (*id - 1, attr_id, &attr_num);
  333. CHECKstatus (status, rcode);
  334.  
  335. attrNum = attr_num - 1;
  336.  
  337. /******************************************************************************
  338. * Determine entry number.
  339. ******************************************************************************/
  340.  
  341. status = CDFV1attrEntryNum (*id - 1, entry_id, &entry_num);
  342. CHECKstatus (status, rcode);
  343.  
  344. entryNum = entry_num - 1;
  345.  
  346. /******************************************************************************
  347. * Get info for this attribute.  Check for incompatibility and get data type.
  348. ******************************************************************************/
  349.  
  350. status = getAttrInfo (*id - 1, attrNum, &entryDataType, &numElements);
  351. CHECKstatus (status, rcode);
  352.  
  353. /******************************************************************************
  354. * Check if data type for entry should be changed to CDF_EPOCH.
  355. ******************************************************************************/
  356.  
  357. #if NSSDC_STANDARD
  358. status = CDFlib (SELECT_, CDF_, *id - 1,
  359.               ATTR_, attrNum,
  360.          GET_, ATTR_NAME_, attrName,
  361.          NULL_);
  362. CHECKstatus (status, rcode);
  363.  
  364. if ((strcmpITB(attrName,"VALIDMIN") == 0 ||
  365.      strcmpITB(attrName,"VALIDMAX") == 0 ||
  366.      strcmpITB(attrName,"SCALEMIN") == 0 ||
  367.      strcmpITB(attrName,"SCALEMAX") == 0) &&
  368.     (entryDataType == CDF_REAL8 || entryDataType == CDF_DOUBLE)) {
  369.   status = CDFlib (SELECT_, CDF_, *id - 1,
  370.                 VAR_, entryNum,
  371.            GET_, VAR_NAME_, varName,
  372.              VAR_DATATYPE_, &varDataType,
  373.            NULL_);
  374.   if (status != NO_SUCH_VAR) {
  375.     CHECKstatus (status, rcode);
  376.  
  377.     if (strcmpITB(varName,"EPOCH") == 0 &&
  378.         (varDataType == CDF_REAL8 || varDataType == CDF_DOUBLE))
  379.       entryDataType = CDF_EPOCH;
  380.   }
  381. }
  382. #endif
  383.  
  384. /******************************************************************************
  385. * Put to the attribute.
  386. ******************************************************************************/
  387.  
  388. status = CDFlib (SELECT_, CDF_, *id - 1,
  389.               ATTR_, attrNum,
  390.               ENTRY_, entryNum,
  391.          PUT_, ENTRY_DATA_, entryDataType, numElements,
  392.                        (entryDataType == CDF_CHAR ?
  393.                        DESCRtoREF(value) : value),
  394.          NULL_);
  395. *rcode = CDFrcode (status);
  396.  
  397. return;
  398. }
  399.  
  400. /******************************************************************************
  401. *  CDF_attr_get.
  402. ******************************************************************************/
  403.  
  404. void CDF_attr_get (id, attr_id, entry_id, value, rcode)
  405. long      *id;           /* in: CDF identifier */
  406. void      *attr_id;       /* in: attribute identifier - could be
  407.                   1) attribute number, or
  408.                   2) attribute name - in VMS passed by
  409.                      reference or descriptor */
  410. void      *entry_id;       /* in: entry identifier - could be
  411.                   1) entry/variable number, or
  412.                   2) variable name - in VMS passed by
  413.                      reference or descriptor */
  414. void      *value;       /* out: attribute value, passing out is
  415.                    always done by reference (as stated in
  416.                    the CDF V1.1 Implementer's Guide) */
  417. long      *rcode;       /* out: CDF return code */
  418. {
  419. long    attr_num;        /* FORTRAN-style */
  420. long    entry_num;        /* FORTRAN-style */
  421. long    attrNum;        /* C-style */
  422. long    entryNum;        /* C-style */
  423. long    dataType;
  424. long    numElements;
  425. CDFstatus status;
  426.  
  427. /******************************************************************************
  428. * Determine attribute number.
  429. ******************************************************************************/
  430.  
  431. status = CDFV1attrNum (*id - 1, attr_id, &attr_num);
  432. if (status < CDF_WARN) {
  433.   *rcode = CDFrcode (status);
  434.   return;
  435. }
  436. else
  437.   attrNum = attr_num - 1;
  438.  
  439. /******************************************************************************
  440. * Determine entry number.
  441. ******************************************************************************/
  442.  
  443. status = CDFV1attrEntryNum (*id - 1, entry_id, &entry_num);
  444. if (status < CDF_WARN) {
  445.   *rcode = CDFrcode (status);
  446.   return;
  447. }
  448. else
  449.   entryNum = entry_num - 1;
  450.  
  451. /******************************************************************************
  452. * Get info for this attribute.
  453. ******************************************************************************/
  454.  
  455. *rcode = CDFrcode (getAttrInfo (*id - 1, attrNum,
  456.                 &dataType,
  457.                 &numElements));    /* check for incompatibility */
  458.  
  459. /******************************************************************************
  460. * Get from the attribute.  The value is assumed to be passed by reference as
  461. * stated in the CDF V1.1 Implementor's Guide.
  462. ******************************************************************************/
  463.  
  464. if (*rcode == CDFV1_OK)
  465.   *rcode = CDFrcode
  466.          (CDFlib (SELECT_, CDF_, *id - 1,
  467.                    ATTR_, attrNum,
  468.                    ENTRY_, entryNum,
  469.               GET_, ENTRY_DATA_, value,
  470.               NULL_));
  471. return;
  472. }
  473.  
  474.  
  475. /******************************************************************************
  476. *  CDF_var_create.
  477. ******************************************************************************/
  478.  
  479. void CDF_var_create (id, var_mnemonic, data_type, num_bytes,
  480.              record_variance, dim_variances, rcode)
  481. long     *id;            /* in: CDF identifier */
  482. void     *var_mnemonic;     /* in: attribute name
  483.                    - in VMS may be passed by reference
  484.                      or descriptor */
  485. void     *data_type;        /* in: CDF Version 1 style data type
  486.                    - in VMS may be passed by reference
  487.                      or descriptor */
  488. long      *num_bytes;        /* in: number of bytes in data type (CDF
  489.                    Version 1 style) - only applies to
  490.                    STRING (CDF_CHAR) data type */
  491. long      *record_variance; /* in: record variance */
  492. long      dim_variances[];  /* in: dimension variances */
  493. long      *rcode;        /* out: CDF return code */
  494. {
  495. long    varNum;        /* C-style */
  496. long    dataType;
  497. char    *varName;
  498. CDFstatus status;
  499.  
  500. dataType = CDFV2dataType (DESCRtoREFnul(data_type,CDFV1_DATA_TYPE_LEN));
  501. varName = DESCRtoREFnul (var_mnemonic, CDFV1_VAR_NAME_LEN);
  502.  
  503. #if NSSDC_STANDARD
  504. if (strcmpITB(varName,"EPOCH") == 0 && dataType == CDF_REAL8)
  505.   dataType = CDF_EPOCH;
  506. #endif
  507.  
  508. status = CDFlib (SELECT_, CDF_, *id - 1,
  509.          CREATE_, VAR_, varName,  dataType,
  510.                 (dataType == CDF_CHAR ? *num_bytes : 1),
  511.                 *record_variance, dim_variances, &varNum,
  512.          NULL_);
  513. *rcode = CDFrcode (status);
  514. return;
  515. }
  516.  
  517. /******************************************************************************
  518. *  CDF_var_inquire.
  519. ******************************************************************************/
  520.  
  521. void CDF_var_inquire (id, var_id, var_num, var_mnemonic, data_type, num_bytes,
  522.               record_variance, dim_variances, rcode)
  523. long      *id;            /* in: CDF identifier */
  524. void      *var_id;        /* in: variable identifier - could be
  525.                    1) variable number, or
  526.                    2) variable name - in VMS passed by
  527.                       reference or descriptor */
  528. long      *var_num;        /* out: variable number, FORTRAN-style */
  529. char      *var_mnemonic;    /* out: variable mnemonic - in VMS assumed to be
  530.                     passed out by reference as stated in CDF
  531.                     V1.1 Implementer's Guide */
  532. char      *data_type;        /* out: CDF Version 1 style data type,
  533.                     assumed to be passed out by reference as
  534.                     stated in CDF V1.1 Implementer's Guide */
  535. long       *num_bytes;        /* out: number of bytes in data type (CDF
  536.                     Version 1 style) */
  537. long      *record_variance; /* out: record variance */
  538. long      dim_variances[];  /* out: dimension variances */
  539. long      *rcode;        /* out: CDF return code */
  540. {
  541. char        varName[CDF_VAR_NAME_LEN+1];
  542. long        dataType;
  543. long        numElements;
  544. long        i;
  545. CDFstatus    status;
  546.  
  547. /******************************************************************************
  548. * Determine variable number.
  549. ******************************************************************************/
  550.  
  551. status = CDFV1varNum (*id - 1, var_id, var_num);
  552. if (status < CDF_WARN) {
  553.   *rcode = CDFrcode (status);
  554.   return;
  555. }
  556.  
  557. /******************************************************************************
  558. * Inquire variable.
  559. ******************************************************************************/
  560.  
  561. *rcode = CDFrcode
  562.        (CDFlib (SELECT_, CDF_, *id - 1,
  563.                  VAR_, *var_num - 1,
  564.             GET_, VAR_NAME_, varName,
  565.               VAR_DATATYPE_, &dataType,
  566.               VAR_NUMELEMS_, &numElements,
  567.               VAR_RECVARY_, record_variance,
  568.               VAR_DIMVARYS_, dim_variances,
  569.             NULL_));
  570.  
  571. if (*rcode == CDFV1_OK)
  572.    {
  573.    /***************************************************************************
  574.    *  copy variable name padding with blanks if necessary (note that the name
  575.    *  may be truncated since CDF V2 names can be longer than CDF V1 names)
  576.    ***************************************************************************/
  577.  
  578.    strncpy (var_mnemonic, varName, CDFV1_VAR_NAME_LEN);
  579.  
  580.    for (i = strlen(varName); i < CDFV1_VAR_NAME_LEN; i++)
  581.       var_mnemonic[i] = ' ';
  582.  
  583.    /***************************************************************************
  584.    *  determine data_type and num_bytes
  585.    ***************************************************************************/
  586.  
  587.    CDFV1_data_type (dataType, numElements, data_type, num_bytes);
  588.    }
  589.  
  590. return;
  591. }
  592.  
  593. /******************************************************************************
  594. *  CDF_var_put.
  595. ******************************************************************************/
  596.  
  597. void CDF_var_put (id, var_id, record_num, indices, value, rcode)
  598. long      *id;            /* in: CDF identifier */
  599. void      *var_id;        /* in: variable identifier - could be
  600.                    1) variable number, or
  601.                    2) variable name - in VMS passed by
  602.                       reference or descriptor */
  603. long      *record_num;        /* in: record number (CDF V1 style, starts
  604.                    at 1) */
  605. long      indices[];        /* in: dimension indices (CDF V1 style,
  606.                    each start at 1) */
  607. void      *value;        /* in: variable value, for now always
  608.                    assume passed by reference (this
  609.                    assumption is not made for an
  610.                    attribute put) */
  611. long      *rcode;        /* out: CDF return code */
  612. {
  613. long        dim_n;
  614. long        Cindices[CDF_MAX_DIMS];
  615. long        varNum;                /* C-style */
  616. long        recNum;                /* C-style */
  617. long        recVary;
  618. long        numDims;
  619. long        dimVarys[CDF_MAX_DIMS];
  620. long        var_num;            /* FORTRAN-style */
  621. long        rec_num;            /* FORTRAN-style */
  622. CDFstatus    status;
  623.  
  624. /******************************************************************************
  625. * Determine variable number.
  626. ******************************************************************************/
  627.  
  628. status = CDFV1varNum (*id - 1, var_id, &var_num);
  629.  
  630. if (status < CDF_WARN) {
  631.   *rcode = CDFrcode (status);
  632.   return;
  633. }
  634. else
  635.   varNum = var_num - 1;
  636.  
  637. /******************************************************************************
  638. * Calculate record number and indices.  Setting the record number and/or
  639. * indices to 0 if the variances are FALSE (NOVARY) is done because some
  640. * applications didn't pass in valid values.  This way the V2.x library won't
  641. * return an error.
  642. ******************************************************************************/
  643.  
  644. status = CDFlib (SELECT_, CDF_, *id - 1,
  645.               VAR_, varNum,
  646.          GET_, CDF_NUMDIMS_, &numDims,
  647.                VAR_RECVARY_, &recVary,
  648.                VAR_DIMVARYS_, dimVarys,
  649.          NULL_);
  650. if (status < CDF_WARN) {
  651.   *rcode = CDFrcode (status);
  652.   return;
  653. }
  654.  
  655. if (recVary)
  656.   recNum = *record_num - 1;
  657. else
  658.   recNum = 0;
  659.  
  660. for (dim_n = 0; dim_n < numDims; dim_n++)
  661.    if (dimVarys[dim_n])
  662.      Cindices[dim_n] = indices[dim_n] - 1;    /* index from 0 for CDF V2 */
  663.    else
  664.      Cindices[dim_n] = 0;
  665.  
  666. /******************************************************************************
  667. * Put to variable.
  668. ******************************************************************************/
  669.  
  670. *rcode = CDFrcode
  671.        (CDFlib (SELECT_, CDF_, *id - 1,
  672.                  CDF_RECNUMBER_, recNum,
  673.                  CDF_DIMINDICES_, Cindices,
  674.             PUT_, VAR_DATA_, value,        /* by REF always */
  675.             NULL_));
  676. return;
  677. }
  678.  
  679. /******************************************************************************
  680. *  CDF_var_get.
  681. ******************************************************************************/
  682.  
  683. void CDF_var_get (id, var_id, record_num, indices, value, rcode)
  684. long      *id;            /* in: CDF identifier */
  685. void      *var_id;        /* in: variable identifier - could be
  686.                    1) variable number, or
  687.                    2) variable name - in VMS passed by
  688.                       reference or descriptor */
  689. long      *record_num;        /* in: record number (CDF V1 style, starts
  690.                    at 1) */
  691. long      indices[];        /* in: dimension indices (CDF V1 style,
  692.                    each start at 1) */
  693. void      *value;        /* out: variable value, always assumed
  694.                     passed out by reference */
  695. long      *rcode;        /* out: CDF return code */
  696. {
  697. long        dim_n;
  698. long        Cindices[CDF_MAX_DIMS];        /* C-style */
  699. long        varNum;                /* C-style */
  700. long        recNum;                /* C-style */
  701. long        numDims;
  702. long        recVary;
  703. long        dimVarys[CDF_MAX_DIMS];
  704. long        var_num;            /* FORTRAN-style */
  705. CDFstatus    status;
  706.  
  707. /******************************************************************************
  708. * Determine variable number.
  709. ******************************************************************************/
  710.  
  711. status = CDFV1varNum (*id - 1, var_id, &var_num);
  712.  
  713. if (status < CDF_WARN) {
  714.   *rcode = CDFrcode (status);
  715.   return;
  716. }
  717. else
  718.   varNum = var_num - 1;
  719.  
  720. /******************************************************************************
  721. * Calculate record number and indices.  Setting the record number and/or
  722. * indices to 0 if the variances are FALSE (NOVARY) is done because some
  723. * applications didn't pass in valid values.  This way the V2.x library won't
  724. * return an error.
  725. ******************************************************************************/
  726.  
  727. status = CDFlib (SELECT_, CDF_, *id - 1,
  728.               VAR_, varNum,
  729.          GET_, CDF_NUMDIMS_, &numDims,
  730.                VAR_RECVARY_, &recVary,
  731.                VAR_DIMVARYS_, dimVarys,
  732.          NULL_);
  733. if (status < CDF_WARN) {
  734.   *rcode = CDFrcode (status);
  735.   return;
  736. }
  737.  
  738. if (recVary)
  739.   recNum = *record_num - 1;
  740. else
  741.   recNum = 0;
  742.  
  743. for (dim_n = 0; dim_n < numDims; dim_n++)
  744.    if (dimVarys[dim_n])
  745.      Cindices[dim_n] = indices[dim_n] - 1;    /* index from 0 for CDF V2 */
  746.    else
  747.      Cindices[dim_n] = 0;
  748.  
  749. /******************************************************************************
  750. * Get from variable.
  751. ******************************************************************************/
  752.  
  753. *rcode = CDFrcode
  754.        (CDFlib (SELECT_, CDF_, *id - 1,
  755.                  CDF_RECNUMBER_, recNum,
  756.                  CDF_DIMINDICES_, Cindices,
  757.             GET_, VAR_DATA_, value,          /* by REF always */
  758.             NULL_));
  759. return;
  760. }
  761.  
  762. /******************************************************************************
  763. *  CDFV2dataType.
  764. *    Determine CDF V2 style data type from a CDF V1 style data type.
  765. ******************************************************************************/
  766.  
  767. long CDFV2dataType (V1_data_type)
  768. char *V1_data_type;
  769. {
  770.  
  771. if (strncmp(V1_data_type,"BYTE",4) == 0) return CDF_BYTE;
  772. if (strncmp(V1_data_type,"INT*2",5) == 0) return CDF_INT2;
  773. if (strncmp(V1_data_type,"INT*4",5) == 0) return CDF_INT4;
  774. if (strncmp(V1_data_type,"REAL*4",6) == 0) return CDF_REAL4;
  775. if (strncmp(V1_data_type,"REAL*8",6) == 0) return CDF_REAL8;
  776. if (strncmp(V1_data_type,"STRING",6) == 0) return CDF_CHAR;
  777.  
  778. return CDF_ILLEGAL_DATATYPE;
  779. }
  780.  
  781. /******************************************************************************
  782. * CDFV1varNum.
  783. *   Determine a CDF V1 style variable number given a CDF V1 style variable
  784. * id which could be either a number or a name (in VMS, passed by either
  785. * reference or descriptor).
  786. ******************************************************************************/
  787.  
  788. CDFstatus CDFV1varNum (id, ptr, var_num)
  789. CDFid    id;
  790. void    *ptr;
  791. long    *var_num;
  792. {
  793. long    varNum;        /* C-style variable number */
  794.  
  795. memmove (var_num, ptr, sizeof(long));
  796.  
  797. if (*var_num <= CDF_MAX_VARS)
  798.   return CDF_OK;            /* assumed to be a number already
  799.                        - this could fail if a variable
  800.                          name of only 1 character was
  801.                          passed in as the variable id */
  802. else
  803.   {
  804.   CDFstatus status;
  805.   status = CDFlib (SELECT_, CDF_, id,
  806.            GET_, VAR_NUMBER_, DESCRtoREFnul(ptr,CDFV1_VAR_NAME_LEN),
  807.                   &varNum,
  808.            NULL_);
  809.   *var_num = varNum + 1;
  810.   return status;
  811.   }
  812. }
  813.  
  814. /******************************************************************************
  815. *  CDFV1attrNum.
  816. *    Determine a CDF V1 style attribute number given a CDF V1 style attribute
  817. *  id which could be either a number or a name (in VMS passed by either
  818. *  reference or descriptor).
  819. ******************************************************************************/
  820.  
  821. CDFstatus CDFV1attrNum (id, ptr, attr_num)
  822. CDFid    id;
  823. void    *ptr;
  824. long    *attr_num;
  825. {
  826. long    attrNum;    /* C-style attribute number */
  827.  
  828. memmove (attr_num, ptr, sizeof(long));
  829.  
  830. if (*attr_num <= TWO_BLANKS)
  831.   return CDF_OK;            /* assumed to be a number already
  832.                        - this could fail if an attribute
  833.                          name of only 1 character was
  834.                          passed in as the attribute id */
  835. else
  836.   {
  837.   CDFstatus status;
  838.   status = CDFlib (SELECT_, CDF_, id,
  839.            GET_, ATTR_NUMBER_, DESCRtoREFnul(ptr,CDFV1_ATTR_NAME_LEN),
  840.                    &attrNum,
  841.            NULL_);
  842.   *attr_num = attrNum + 1;
  843.   return status;
  844.   }
  845. }
  846.  
  847. /******************************************************************************
  848. *  CDFV1attrEntryNum.
  849. *    Determine a CDF V1 style attribute entry number given a CDF V1 style
  850. *  entry id which could be either a variable number/global entry number or a
  851. *  variable name (in VMS passed by either reference or descriptor).
  852. ******************************************************************************/
  853.  
  854. CDFstatus CDFV1attrEntryNum (id, ptr, entry_num)
  855. CDFid    id;
  856. void    *ptr;
  857. long    *entry_num;
  858. {
  859. long    varNum;        /* C-style variable number */
  860.  
  861. memmove (entry_num, ptr, sizeof(long));
  862.  
  863. if (*entry_num <= TWO_BLANKS)
  864.    return CDF_OK;            /* assumed to be a number already
  865.                        - this could fail if a variable
  866.                          name of only 1 character was
  867.                          passed in as the entry id */
  868. else
  869.   {
  870.   CDFstatus status;
  871.   status = CDFlib (SELECT_, CDF_, id,
  872.            GET_, VAR_NUMBER_, DESCRtoREFnul(ptr,CDFV1_VAR_NAME_LEN),
  873.                   &varNum,
  874.            NULL_);
  875.   *entry_num = varNum + 1;
  876.   return status;
  877.   }
  878. }
  879.  
  880. /******************************************************************************
  881. *  CDFrcode.
  882. *    Translate CDF V2 status code to CDF V1 return code.
  883. ******************************************************************************/
  884.  
  885. long CDFrcode (Status)
  886. CDFstatus Status;
  887. {
  888. if (Status < CDF_WARN)
  889.    switch (Status) {
  890.       case NO_SUCH_VAR:        return CDFV1_NO_SUCH_VAR;
  891.       case NO_SUCH_ATTR:    return CDFV1_NO_SUCH_ATTR;
  892.       case NO_SUCH_ENTRY:    return CDFV1_NO_SUCH_ATTR_ENTRY;
  893.       default:            return CDFV1_DEFAULT_RCODE;
  894.    }
  895.  else
  896.    return CDFV1_OK;
  897. }
  898.  
  899. /******************************************************************************
  900. *  Determine CDF V1 style data type and number of bytes.
  901. ******************************************************************************/
  902.  
  903. void CDFV1_data_type (dataType, STRING_num_bytes, data_type, num_bytes)
  904. long    dataType;       /* CDF V2 style data type */
  905. long    STRING_num_bytes;  /* number of bytes if of "string" data type,
  906.                   otherwise ignored */
  907. char    *data_type;       /* CDF V1 style data type */
  908. long    *num_bytes;       /* CDF V1 style number of bytes */
  909. {
  910.  
  911. switch (dataType)
  912.    {
  913.    case CDF_BYTE:
  914.    case CDF_INT1:
  915.     strncpy (data_type, "BYTE    ", CDFV1_DATA_TYPE_LEN);
  916.     *num_bytes = 1;
  917.     break;
  918.  
  919.    case CDF_INT2:
  920.     strncpy (data_type, "INT*2   ", CDFV1_DATA_TYPE_LEN);
  921.     *num_bytes = 2;
  922.     break;
  923.  
  924.    case CDF_INT4:
  925.     strncpy (data_type, "INT*4   ", CDFV1_DATA_TYPE_LEN);
  926.     *num_bytes = 4;
  927.     break;
  928.  
  929.    case CDF_REAL4:
  930.    case CDF_FLOAT:
  931.     strncpy (data_type, "REAL*4  ", CDFV1_DATA_TYPE_LEN);
  932.     *num_bytes = 4;
  933.     break;
  934.  
  935.    case CDF_REAL8:
  936.    case CDF_DOUBLE:
  937.    case CDF_EPOCH:
  938.     strncpy (data_type, "REAL*8  ", CDFV1_DATA_TYPE_LEN);
  939.     *num_bytes = 8;
  940.     break;
  941.  
  942.    case CDF_CHAR:
  943.    case CDF_UCHAR:
  944.     strncpy (data_type, "STRING  ", CDFV1_DATA_TYPE_LEN);
  945.     *num_bytes = STRING_num_bytes;
  946.     break;
  947.  
  948.    default:
  949.     strncpy (data_type, "ILLEGAL ", CDFV1_DATA_TYPE_LEN);
  950.     *num_bytes = 0;
  951.     break;
  952.    }
  953.  
  954. return;
  955. }
  956.  
  957. #endif
  958.